<template>
  <a-modal v-model:visible="visible" :maskClosable="false" :title="vdata.record.activityName + '-设置函'" :footer="false" width="600px">
    <a-list item-layout="horizontal" :data-source="vdata.record.couponList">
      <template #renderItem="{ item }">
        <a-list-item>
          <a-list-item-meta>
            <template #title>
              <b>{{ item.couponName }}</b>
            </template>
          </a-list-item-meta>
          <template #actions>
            <a-button v-if="item.ossFileUrl" type="link" :href="item.ossFileUrl">查看回执设置函</a-button>
            <a-button type="link" @click="downloadLicense(item.couponId,item.couponName)">下载设置函</a-button>
            <a-button type="link" @click="downloadMch(item.couponId,item.couponName)">下载可核销商户</a-button>
          </template>
        </a-list-item>
      </template>
    </a-list>
  </a-modal>
</template>

<script setup>
import { ref, reactive, defineExpose } from 'vue'
import fileDownload from 'js-file-download'
import { exportExcelUrl, $exportExcel } from '@/api/activityManage/activityExamine/index'

const visible = ref(false)

const vdata = reactive({
  record: {}, // 下载设置函数据
})

// 下载设置函
function downloadLicense(couponId,couponName){
  $exportExcel(exportExcelUrl.license, { couponId, activityId: vdata.record.activityId }, 'POST').then(res => {
    fileDownload(res.data, `${vdata.record.activityName}-${couponName}-设置函.doc`)
  })
}
// 下载可核销商户
function downloadMch(couponId,couponName){
  $exportExcel(exportExcelUrl.canUsedMch, { couponId }, 'POST').then(res => {
    fileDownload(res.data, `${vdata.record.activityName}-${couponName}-可核销商户.xlsx`)
  })
}

function show(record) {
  vdata.record = record
  visible.value = true
}

defineExpose({
  show
})

</script>

<style lang="less" scoped>

</style>